use std::io;
use std::cmp::Ordering;
use rand::Rng;



fn main() {
    println!("guess the number!");

    // 生成随机数
    let secret_number = rand::thread_rng().gen_range(1..101);

    loop {
        println!("please input your guess.");
        // 定义一个变量
        let mut guess = String::new();
        io::stdin()
            .read_line(&mut guess)
            .expect("failed to read line");

        // 类型转换
        let guess: u32 = match guess.trim().parse(){
            Ok(num) => num,
            Err(_) => continue
        };
            // .expect("please type a number !"); // 设置错误信息

        println!("you guessed :{}", guess);
        println!("secret number is :{}",secret_number);

        // 进行比较
        match guess.cmp(&secret_number){
            Ordering::Less => println!(" too small!"),
            Ordering::Greater => println!(" too big !"),
            Ordering::Equal => {
                println!(" you win !");
                break
            },
        }
    }



}
